const https = require('https');
const fs = require('fs');
const path = require('path');

const textures = [
  {
    url: 'https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_atmos_2048.jpg',
    filename: 'earth-texture.jpg'
  },
  {
    url: 'https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_normal_2048.jpg',
    filename: 'earth-normal.jpg'
  },
  {
    url: 'https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_specular_2048.jpg',
    filename: 'earth-specular.jpg'
  },
  {
    url: 'https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_clouds_1024.jpg',
    filename: 'earth-clouds.jpg'
  }
];

const downloadFile = (url, filename) => {
  const filepath = path.join(__dirname, 'public', 'assets', filename);
  const file = fs.createWriteStream(filepath);

  https.get(url, (response) => {
    response.pipe(file);
    file.on('finish', () => {
      file.close();
      console.log(`Downloaded ${filename}`);
    });
  }).on('error', (err) => {
    fs.unlink(filepath);
    console.error(`Error downloading ${filename}: ${err.message}`);
  });
};

textures.forEach(texture => {
  downloadFile(texture.url, texture.filename);
}); 